function loadResource(path) {
    return new Promise((resolve, reject) => {
        //console.log(path)
        $.ajax({
            url:'img/'+path,
            dataType:'text',
            success: function (text) {
                let json = eval(`(${text})`);

                let res = {};
                let count = 0, total = 0;
                for (let name in json) {
                    total++;
                    let oImg = new Image();
                    oImg.src = 'img/' + json[name].src;
                    oImg.onload = function () {
                        res[name] = {
                            img: this,
                            frame: json[name].frame
                        };

                        count++;

                        if (count === total) {
                            resolve(res)
                        }
                    }
                }
            },
            error(e){
                reject(e)
                console.log(e)
            }
        })
    })
}

async function loadResources() {
    let src = {
        bottom: 'bottom.json',
        cannon: 'cannon.json',
        bullet: 'bullet.json',
        coin: 'coin.json',
        fish: 'fish.json',
        number: 'number.json',
        web: 'web.json',
    };
    let imgs = {};
    try{
        for (let name in src) {
            imgs[name] = await loadResource(src[name]);
        }

        window.__g_resource = imgs;
        //return imgs;
    }catch (e) {
        console.error(e)
        // throw Error()
    }
}
